package com.atom.common.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

public class ResponseUtil {
  
  private static Logger logger = Logger.getLogger(ResponseUtil.class);

  public static void responseHtml(HttpServletResponse response, File file) {
    InputStream in = null;
    response.setContentType("text/html; charset=utf-8");
    OutputStream out = null;
    try {
      in = new FileInputStream(file);
      out = response.getOutputStream();

      int ch;
      while ((ch = in.read()) != -1) {
        out.write(ch);
      }
      out.flush();
      out.close();
      in.close();
    } catch (IOException e) {
      logger.error("error message = {}" + e.getMessage(), e);
    } 
    finally {
      try {
        if (out != null) {
          out.close();
        }
        if (in != null) {
          in.close();
        } 
        file.delete();
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }

}
